package com.nsl.my_youlai.Jackson.online2_ok;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nsl.my_youlai.Jackson.online.UseDocxStatusEnum;
import com.nsl.my_youlai.common.enums.DocxTemplateStatusEnum;
import com.nsl.my_youlai.model.bo.DocxTemplateBo;
import com.nsl.my_youlai.mystar.NslUtilPrinter;
import com.nsl.my_youlai.mystar.enums.NslEnumBaseI;
import org.junit.jupiter.api.Test;


public class Demo1 {

    //ok
    @Test
    public void demo1() throws JsonProcessingException {
        Distance distance1=Distance.MILE;
        ObjectMapper objectMapper=new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(distance1));

        String json="{\"unit\":\"miles\",\"meters\":1609.34}";

        Distance distanceResult=objectMapper.readValue(json,Distance.class);
        System.out.println(distanceResult);
    }

    //反序列化没问题
    @Test
    public void test2() throws JsonProcessingException {
        UseDistance useDistance=new UseDistance();
        useDistance.setX("abc");
        useDistance.setDistanceEnum(Distance.METER);

        ObjectMapper objectMapper=new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(useDistance));

        String jsonString="{\"x\":\"abc\",\"distanceEnum\":{\"unit\":\"meters\",\"meters\":1.0}}";
        ObjectMapper objectMapper2=new ObjectMapper();
        UseDistance useDistance1=objectMapper2.readValue(jsonString,UseDistance.class);
        System.out.println(useDistance1);
    }

    @Test
    public void test3() throws JsonProcessingException {
        UseDocxStatusEnum bo=new UseDocxStatusEnum();
        bo.setStatusEnum(DocxTemplateStatusEnum.EDIT);
        ObjectMapper objectMapper=new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(bo));
        String json="{\"statusEnum\":{\"value\":1,\"label\":\"启用\",\"enumList\":[{\"value\":\"1\",\"label\":\"启用\"},{\"value\":\"0\",\"label\":\"禁用\"}],\"labelRangeAsString\":\"[启用, 禁用]\"},\"xstring\":null}";
        UseDocxStatusEnum bo2=objectMapper.readValue(json,UseDocxStatusEnum.class);
        NslUtilPrinter.printWithFastJsonPrettyAndNUll(bo2);
    }

    @Test
    public void test4() throws JsonProcessingException {
        DocxTemplateBo bo=new DocxTemplateBo();
        bo.setStatusEnum(DocxTemplateStatusEnum.EDIT);
        ObjectMapper objectMapper=new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(bo));
        String json="{\"uuid\":null,\"templateSn\":null,\"majorCategoryFirstLevelId\":null,\"majorCategoryFirstLevelLabel\":null,\"majorCategorySecondLevelLabel\":null,\"majorCategorySecondLevelId\":null,\"authorName\":null,\"templateDocxName\":null,\"templateExcelName\":null,\"version\":null,\"description\":null,\"templateDocxFilePath\":null,\"templateExcelFilePath\":null,\"templateDocxMd5\":null,\"templateExcelMd5\":null,\"regionLevel1\":null,\"createTime\":null,\"updateTime\":null,\"statusEnum\":{\"value\":1,\"label\":\"编辑\",\"labelRangeAsString\":\"[编辑, 启用]\",\"enumList\":[{\"value\":\"1\",\"label\":\"编辑\"},{\"value\":\"0\",\"label\":\"启用\"}]}}";
        DocxTemplateBo bo2=objectMapper.readValue(json,DocxTemplateBo.class);
        NslUtilPrinter.printWithJacksonPretty(bo2);
    }

    @Test
    public void test5() throws JsonProcessingException {
        System.out.println(NslEnumBaseI.getEnumList(DocxTemplateStatusEnum.class));
        NslUtilPrinter.printWithJacksonPretty(NslEnumBaseI.getElRadioOptionList(DocxTemplateStatusEnum.class));
    }
}
